#include "application.h"

Application::Application()
{
	/*Read application configuration from default path before initialization*/
	m_appconfig = new AppConfig();
	m_appconfig->read();
	//m_appconfig->make_config();

	create();
}

Application::Application(int argc, char** argv) 
	:Application()
{ 

}

Application::Application(HINSTANCE hinstance, wchar_t* cmdline)
	:Application()
{ 

} 

Application::~Application()
{
	/*Save application configuration to default path before closing*/
	m_appconfig->save();
}

void Application::create()
{
	if (!create_device(m_appconfig->get_config()))
	{
		
	}

	if (!create_audio_system(m_appconfig->get_config()))
	{

	}
  
}

bool Application::create_device(st_config &config)
{
	m_device= createDevice(
		config.video_api,
		config.screen_resolution,
		config.color_depth,
		config.is_fullscreen,
		config.is_stencilbuffer,
		config.is_vsync,
		&m_event_handler
		);

	if (m_device == NULL)
		return false;
 
	m_device->setWindowCaption(config.app_title.c_str());
	m_device->setWindowStyle(true,false); 

	m_driver = m_device->getVideoDriver();
	m_scene_mgr = m_device->getSceneManager();
	m_env = m_device->getGUIEnvironment();

	return true;
}

bool Application::create_audio_system(st_config &config)
{
	return true;
}

void Application::run()
{
	for (; m_device->run();)
	{
		update();
		render();
	} 
}

void Application::update()
{

}

void Application::render()
{
	m_driver->beginScene(true, true, video::SColor(255, 155,0,110));
	
	m_driver->endScene();
}

